<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title">学生管理</h3>

                <div class="box-tools">
                    
                    <div class="input-group input-group-sm" style="width: 300px;">
                        <form>
                        <input type="text" name="table_search" class="form-control pull-right" placeholder="学生姓名">
                        </form>
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default" data-url="{{ url('admin/children/search') }}" onclick="postfun(this)" style="margin-right: 10px"><i class="fa fa-search"></i></button>
                            <button class="btn btn-success" data-url="{{ url('/admin/children/create') }}" onclick="jumpfun(this)">添加</button>
                        </div>
                    </div>
                    
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
                <table class="table table-hover">
                    <tr>
                        <th>ID</th>
                        <th>学生姓名</th>
                        <th>小名</th>
                        <th>性别</th>
                        <th>出生日期</th>
                        <th>创建时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    @foreach($children as $child)
                    <tr>
                        <td>{{ $child->id }}</td>
                        <td>{{ $child->name }}</td>
                        <td>{{ $child->nice_name }}</td>
                        <td>{{ $child->sex?'男':'女' }}</td>
                        <td>{{ $child->birthday }}</td>
                        <td>{{ $child->created_at }}</td>
                        <td id="status_td_{{ $child->id }}">{!! $child->status?"<span class='label label-success'>正常</span>":"<span class='label label-danger'>离开</span>" !!}</td>
                        <td>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/children', $child->id.'/edit') }}" onclick="jumpfun(this)" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/users/card', $child->id) }}" onclick="jumpfun(this)" class="X-Small btn-xs text-fuchsia "><i class="fa fa-plus"></i> 充值</a>
                            <a id="status_a_{{ $child->id }}" style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/children', $child->id) }}" onclick="leave(this)" class="X-Small btn-xs text-danger ">
                                {!! $child->status?'<i class="fa fa-remove"></i> 离开':'' !!}
                            </a>
                            <a style="margin:3px;" href="javascript:void(0)" data-url="{{ url('/admin/card/list', $child->id) }}" onclick="jumpfun(this)" class="X-Small btn-xs text-warning "><i class="fa fa-edit"></i> 充值记录</a>
                        </td>
                    </tr>
                    @endforeach
                </table>
            </div>
            <div class="box-footer clearfix">
                <ul class="pagination pagination-sm no-margin pull-right">
                    {!! $children->links('vendor.pagination.pages') !!}
                </ul>
            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.box -->
    </div>
</div>
<script>
    function leave(obj) {
        swal({
                title: "确定让该学员离开吗?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "执行",
                closeOnConfirm: false
            },
            function(){
                $.ajax({
                    url: $(obj).attr('data-url'),
                    type: "DELETE",
                    dataType: "json",
                    success: function(data) {
                        if(data.code == 1){
                            swal("操作成功!", "", "success");
                            var x = $(obj).attr("id").lastIndexOf("_");
                            var id = $(obj).attr("id").substr(x+1);
                            $("#status_td_"+id).html("<span class='label label-danger'>离开</span>");
                            $("#status_a_"+id).html("");
                        }else {
                            swal("操作失败!", "参数错误", "error");
                        }
                    }
                });
            })
    }
</script>